<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %>
<%@ include file="/common/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<head>
    <meta charset="utf-8"/>
    <title>发布评论</title>
    <%@ include file="/common/styles.jsp" %>
    <%@ include file="/common/style/fileupload.jsp" %>
</head>
<body>
<s:action name="product-order!view" executeResult="false" namespace="/h5" var="view"/>


<div class="pg-productcomment f-fs2">
    <div class="m-add">
        <div class="u-texra">
            <div class="hd">输入评论内容</div>
            <textarea placeholder="请评价${view.productOrder.no}订单" id="neirong"></textarea>
        </div>
        <%--<div class="u-imgs f-cb">--%>
            <%--<div id="addbutton" style="cursor: pointer"--%>
                 <%--onclick="moreImgFileUp('img1','img2','fileupload','clickCount','addbutton','imgs');">--%>
                <%--<span style="display: none;">--%>
                    <%--<img src="" id="img2">--%>
                <%--</span>--%>
                <%--<span id="img1">--%>
                      <%--<i class="iconfont icon-tianjiatupian"></i>--%>
                <%--</span>--%>
            <%--</div>--%>
            <%--<input id="fileupload" name="file" style="cursor: pointer" hidden="hidden" type="file"/>--%>
            <%--<input id="imgs" type="hidden" value="">--%>
            <%--<input type="hidden" id="clickCount" value="0">--%>
            <%--<input id="imgCount" value="5" type="hidden">--%>
        <%--</div>--%>
        <%--<div class="u-imgup">--%>

            <%--<div class="tex">--%>
                <%--<p>添加图片,建议最多5张</p>--%>
                <%--<span>把您的美好体验分享给其他小伙伴吧~</span>--%>
            <%--</div>--%>
        <%--</div>--%>
    </div>

    <div class=""></div>
</div>
<div class="m-bottom-bts">
    <a class="u-btn u-btn-danger f-fs2" id="commentButton" onclick="comment();">提交评论</a>
</div>
<%@ include file="/common/scripts.jsp" %>
<%@ include file="/common/script/fileupload.jsp" %>
<script>
    //多张图片删除
    $("body").on("click", "[id^='deleteImg']", function () {
        var _count = $(this).attr("id").replace("deleteImg", "");
        $("#img" + _count).slideUp("quick");
        var oldImg = $("#newImg" + _count).attr("src");
        oldImg = oldImg.replace("!small.jpg", "");
        $("#imgs").val($("#imgs").val().replace(oldImg + ",", ""));
        var _imgCount = $("#imgCount").val();
        $("#imgCount").val(Number(_imgCount) + 1);
    });
    //    function deleteImg() {
    //        var _count = $(this).attr("id").replace("deleteImg", "");
    //        $("#img" + _count).slideUp("quick");
    //        var oldImg = $("#newImg" + _count).attr("src");
    //        oldImg = oldImg.replace("!small.jpg", "");
    //        $("#imgs").val($("#imgs").val().replace(oldImg + ",", ""));
    //        var _imgCount = $("#imgCount").val();
    //        $("#imgCount").val(Number(_imgCount) + 1);
    //    }

    //多图上传
    function moreImgFileUp(_img1, _img2, _fileupload, _clickCount, _addbutton, _imgs) {
        var url = 'http://up.qiniu.com/';
        if (!$("#" + _img1).is(":hidden")) {
            $("#" + _fileupload).click();
            var _count = $("#" + _clickCount).val();
            $("#" + _clickCount).val(_count + 1);
            $("#" + _img1).hide();
            $("#" + _img2).show();
            var time = new Date();
            key = time.getFullYear() + '/' + (time.getMonth() + 1) + '/' + time.getDate() + '/' + Date.parse(time);
            $("#" + _fileupload).fileupload({
                url: url,
                add: function (e, data) {
                    var uploadErrors = [];
                    var acceptFileTypes = /^image\/(gif|jpe?g|png)$/i;
                    if (data.originalFiles[0]['type'].length && !acceptFileTypes.test(data.originalFiles[0]['type'])) {
                        uploadErrors.push('请确认您上传的文件为图片［仅支持PNG，JPG，JEPG格式］');
                    }
                    if (data.originalFiles[0]['size'].length && data.originalFiles[0]['size'] > 5000000) {
                        uploadErrors.push('抱歉，文件太大');
                    }
                    if (uploadErrors.length > 0) {
                        layer.msg(uploadErrors.join("\n"));
                    } else {
                        data.submit();
                    }
                },
                dataType: 'json',
                post: 'POST',
                formData: {
                    key: key,
                    token: "<%=cn.org.eshow.component.qiniu.QiniuUtil.uploadToken(QiniuConfig.BUCKET)%>"
                },

                done: function (e, data) {
                    var img = "<%=QiniuConfig.URL%>/" + data.result.key;
                    var htm = shunda.ctx + "/ajax/file/add.jsp?count=" + _count + "&img=" + img;
                    $.get(htm, function (result) {
                        $("#" + _addbutton).before(result);

                        $("#" + _imgs).val($("#" + _imgs).val().replace("<%=QiniuConfig.NONE_IMG%>/", "") + img + ",");
                        var _imgCount = $("#imgCount").val();
                        $("#imgCount").val(Number(_imgCount) - 1);
                        if ($("#imgCount").val() <= 0) {
                            $("#" + _fileupload).attr("disabled", "disabled");
                        } else {
                            $("#" + _fileupload).removeAttr("disabled");
                        }
                    });
                }
            }).prop('disabled', !$.support.fileInput)
                    .parent().addClass($.support.fileInput ? undefined : 'disabled');
            $("#" + _img2).hide();
            $("#" + _img1).show();
        }
    }

    //提交评价
    function comment() {
        var _imgs = $("#imgs").val();
        var _content = $("#neirong").val();
        if (_content == null || _content == '') {
            layer.msg("请填写评论内容");
        } else {
            $.ajax({
                url: "${ctx}/h5/product-comment!comment.action",
                type: "post",
                data: {
                    "id": '${view.productOrder.id}',
                    "productComment.content": _content,
                    "productComment.imgs": _imgs
                },
                dataType: "json",
                success: function (result) {
                    if (result.status != 1) {
                        layer.msg(result.msg);
                    } else {
                        window.location.href = '${ctx}/productOrder/commentSuccess?id=${view.productOrder.id}';
                    }
                }
            });
        }
    }


    <%--$("#commentButton").on("click",function(){--%>
    <%--var _imgs = $("#imgs").val();--%>
    <%--var _content = $("#neirong").val();--%>
    <%--if (_content == null || _content == '') {--%>
    <%--layer.msg("请填写评论内容");--%>
    <%--} else {--%>
    <%--$.ajax({--%>
    <%--url: "${ctx}/h5/product-comment!comment.action",--%>
    <%--type: "post",--%>
    <%--data: {--%>
    <%--"id": '${view.productOrder.id}',--%>
    <%--"productComment.content": _content,--%>
    <%--"productComment.imgs": _imgs--%>
    <%--},--%>
    <%--dataType: "json",--%>
    <%--success: function (result) {--%>
    <%--if (result.status != 1) {--%>
    <%--layer.msg(result.msg);--%>
    <%--} else {--%>
    <%--window.location.href='${ctx}/productOrder/commentSuccess?id=${view.productOrder.id}';--%>
    <%--}--%>
    <%--}--%>
    <%--});--%>
    <%--}--%>
    <%--});--%>
</script>
</body>

